package com.xds.gulimall.ware.vo;

import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author : baixu
 * @date : 10:52 2021/12/23
 * 订单确认页需要的vo
 */
@Data
public class OrderConfirmVo {
    List<MemberAddressVo> address;//收货地址列表
    List<OderItemVo> items;
    Integer integration;//会员积分
    BigDecimal total;//订单总额
    BigDecimal payPrice;//应付价格
    String orderToken;//防止重复提交
    Integer count;
    Map<Long,Boolean> stocks;

    public Integer getCount() {
        Integer i=0;
        if (items!=null) {

            for (OderItemVo item : items) {
                i+=item.getCount();
            }
        }
        return i;
    }

    public BigDecimal getTotal() {
        BigDecimal sum=new BigDecimal("0");
        if (items!=null) {
            for (OderItemVo item : items) {
                BigDecimal multiply=item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
               sum= sum.add(multiply);
            }
        }
        return sum;

    }

    public BigDecimal getPayPrice() {
        return getTotal();
    }

    @Data
    public static class MemberAddressVo{
        @TableId
        private Long id;
        private Long memberId;
        private String name;
        private String phone;
        private String postCode;
        private String province;
        private String city;
        private String region;
        private String detailAddress;
        private String areacode;
        private Integer defaultStatus;

    }
    @Data
    public static class OderItemVo{
        private Long skuId;
        private String title;
        private String image;
        private List<String> skuAttrValues;
        private BigDecimal price;
        private Integer count;
        private BigDecimal totalPrice;
//        private boolean hasStock;
        private BigDecimal weight;

    }

}
